var baseUrl = "http://qlapi.sylu.edu.cn/mock/67";

function send_first() {
    let username = document.getElementById("username").value;
    let password = document.getElementById("password").value;
    console.log(username);
    console.log(password);
    _value = `username=${username}&password=${password}`;
    if (!_value) return false;
    var First_send = null;

    try {
        First_send = new XMLHttpRequest();
    } catch (error) {
        First_send = new ActiveXObject("Microsoft.XMLHTTP");
    }

    First_send.open("post", `${baseUrl}/login`, true);

    First_send.setRequestHeader("content-type", "application/x-www-form-urlencoded");

    First_send.send(`${_value}`);

    First_send.onreadystatechange = function() {
        if (First_send.readyState == 4) {

            if (First_send.status == 200) {
                const res = JSON.parse(First_send.responseText);
                let box = document.getElementById("first");
                let text = box.getElementsByClassName("receive")[0];
                text.innerText = res.msg;
                console.log(text.innerText);
                if (res.code == 200) {
                    alert("登录成功！");
                    window.location.href = "sign_in.html";
                }
            } else {
                alert("Error:" + First_send.status);
            }


        }

    }



}